db.transactions.drop();
db.accounts.drop();
db.accounts.insert({name:"A", balance:1000, pending:[]});
db.accounts.insert({name:"B", balance:1000, pending:[]});

db.transactions.insert({source:"A", destination:"B", value:1000, status:"initial"});

var t = db.transactions.findOne({status:"initial"});
db.transactions.update({_id:t._id}, {$set: {status:"pending"}});
db.accounts.update({name:t.source, pending:{$ne:t._id}}, {$inc: {balance:-t.value}, $push: {pending: t._id}});

